﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BTKERP.BLL.UserMgmt;

namespace BTKERP.MVCWeb.Controllers
{
    public class DashboardController : ControllerBase
    {
        //
        // GET: /Dashboard/

        public ActionResult Index()
        {
            if (SessionEntity == null)
            {
                Response.Redirect("/Default.aspx");
                return new EmptyResult();
            }
            return View(SessionEntity);
        }


        [HttpPost]
        public RedirectResult Login(string username, string password)
        {
            Model.User staff = UserBLL.UserLogin(username, password);
            if (staff == null)
            {
               // Response.Redirect("/Default.aspx?error=1");
                return new RedirectResult("/Default.aspx?error=1");
            }

            Model.Web.SessionEntity session = new Model.Web.SessionEntity();
            session.Staff = staff;

            SessionEntity = session;
            return new RedirectResult("/Dashboard/Index");
        }

        public ActionResult Logout()
        {
            Session.Clear();
            Session.Abandon();
            Response.Redirect("/Default.aspx");
            return new EmptyResult();
        }

    }
}
